package com.zcj.demo.mq;

import com.alibaba.fastjson.JSON;
import com.zcj.demo.mq.dto.SmsSendDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @author 68300119
 * @Date 2021/2/2
 **/
@Component
public class RabbitMqSender {

    private final RabbitTemplate rabbitTemplate;

    public RabbitMqSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * 发送短信
     *
     * @param mobile 手机
     * @param code   验证码
     */
    public void sendSms(String mobile, String code) {
        SmsSendDTO smsSendDTO = new SmsSendDTO(mobile, code);
        rabbitTemplate.convertAndSend("zcj.sms.send", JSON.toJSONString(smsSendDTO));
    }
}
